<!DOCTYPE html>
<html>
    <head>
        <title>Start Page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <script type="text/javascript">
    function connect() {
    	var webScoketUtil = {
    			//缓存数据
    			dataParam:{
    				tdsbids:[],
    				explorer : navigator.userAgent,
//    				path:"192.168.100.106:9081"
    				//path:"192.168.100.51:9003"
    				path:"localhost:8080"
    				//path:runningConfig.demsHttpPath.split("\//")[1]
    			},
    			webscoket:null,
    			//初始化webscoket
    			initWebScoket:function(obj){
    				if(typeof websocket != "undefined"&&websocket.readyState == 1){
    					var jsonObject = obj.onopen();
    					websocket.send(JSON.stringify(jsonObject));
    					return;
    				}
//    				var wsServer ='ws://'+this.dataParam.path + '/webscoket';
    				var wsServer ='ws://'+this.dataParam.path + '/springMvc/websck.do';
    				if ('WebSocket' in window) {
    					websocket = new WebSocket(wsServer);
    				} else if ('MozWebSocket' in window) {
    					websocket = new MozWebSocket(wsServer);
    				} else {
    					alert("do not support this exporler!");
    				}
    				this.webscoket = websocket;
    				//建立webscoket连接
    				this.webscoket.onopen = function(evt) {
    					var jsonObject = obj.onopen();
    					websocket.send(JSON.stringify(jsonObject));
    				};
    				//处理返回数据
    				this.webscoket.onmessage = function(evt){
    					var json = evt.data;
    					console.log("evt",evt);
    					obj.onmessage(json);
    				};
    				this.webscoket.onerror = function(evt){
    					console.log('Error occured: ' + evt.data);
    				};
    			}
    		};

    		 webScoketUtil.initWebScoket({onopen:function(){
    		    	return {type:"00",subType:"99",id:""};
    				},onmessage:function(json){
    					var data = eval("("+json+")");
    					console.log(json);

    			}});
      }
    </script>
    <body>
        <h1>Hello World!</h1>
    </body>
</html>
